<template>
    <view class="login-container" :data-theme="theme()" :class="theme() || ''">
        <view class="skip" @click="gotoPage('/pages/index/index')">{{ $t('login.skip_arrow') }}</view>
        <view class="">
            <view class="login_topbpx">
                <view class="login_tit">{{$t('login.shop_user_login')}}</view>
                <view class="group-bd">
                    <view class="form-level d-s-c">
                        <input class="login-input" type="text" v-model="formData.username"
                            :placeholder="$t('login.enter_account')" />
                    </view>
                    <view class="form-level d-s-c">
                        <input class="login-input" type="text" password="true" v-model="formData.password"
                            :placeholder="$t('login.enter_password')" />
                    </view>
                    <view class="form-level d-s-c">
                        <input class="login-input" type="text" v-model="formData.code" placeholder="请输入验证码" />
                        <image class="img-code" @click="getCode" :src="imgCode"></image>
                    </view>
                </view>
            </view>
        </view>
        <button class="theme-btn sub-btn" @click="formSubmit">
            {{ $t('login.login_now') }}
        </button>
    </view>
</template>
<script>
export default {
    data() {
        return {
            formData: {
                username: '',
                password: '',
                codeKey: '',
                code: ''
            },
            imgCode: ''
        }
    },
    onLoad(options) {
        this.getCode()
    },
    onShow(){
        uni.setNavigationBarTitle({
			title: this.$t('plus.merchant_login')
		})
    },
    methods: {
        formSubmit() {
            const self = this;
            self._supplier_post('passport/login', self.formData, result => {
                // 记录token userId
                uni.setStorageSync("token", result.data.token);
                uni.setStorageSync("userId", result.data.loginSupplierUserVo.supplierUserId);
               uni.navigateTo({ url: '/pages/writeoff/writeoff' })
            })
        },
        getCode() {
            const self = this;
            self._supplier_post("index/base", {}, res => {
                self.imgCode = res.data.codeImage
                self.formData.codeKey = res.data.codeKey
            });
        }
    }
}
</script>
<style lang="scss" scoped>
page {
    background: #ffffff;
}

@import "./login.scss";

.img-code {
    width: 200rpx;
    height: 100rpx;
}
</style>